package cn.com.xy.sms.sdk.util;

import cn.com.xy.sms.sdk.log.LogManager;
import cn.com.xy.sms.sdk.service.baseparse.DataEnCipherApi;

/*
 * DataEnCipher, jni加解密类, 请不要改变此处的类名和包名. 
 * SDK-493 hewngao 20160618 start
 */
public class KeyInitUtil {

    public synchronized static  int setKeyData(byte[] buffer) {
    	DataEnCipherApi.mLocalKey = new byte[buffer.length];
        for (int i = 0; i < buffer.length; i++) {
        	DataEnCipherApi.mLocalKey[i] = buffer[i];
        }
//        LogManager.e("xiaoyuan", "setKeyData: "+buffer);
        return 0;
    }

    public synchronized static int setSDKInitData(String data, int type) {
        if (type == 1) {
        	DataEnCipherApi.mSdkChannel = data;
        }
        if (type == 2) {
        	DataEnCipherApi.mSdkSecritKey = data;
        }
//        LogManager.e("xiaoyuan", "setSDKInitData: "+data+" type: "+type);
        return type;
    }
	/**
	 * 解密数据
	 * @param rawData 待解密的数据
	 * @return
	 */
	public synchronized static String dataDecrypt(String rawData){
		try{
		    return DataEnCipherApi.dataDecrypt(rawData);
		}catch(Throwable e){
			LogManager.e("xiaoyuan", "KeyInitUitl.dataDecrypt ", e);
		}
		return DataEnCipherApi.ERROR_CODE;
	}
	/**
	 * 加密
	 * @param rawData 待解密的数据
	 * @return
	 */
	public synchronized static String dataEncrypt(String rawData){
		try{
		    return DataEnCipherApi.dataEncrypt(rawData);
		}catch(Throwable e){
			LogManager.e("xiaoyuan", "KeyInitUitl.dataEncrypt ", e);
		}
		return DataEnCipherApi.ERROR_CODE;
	}
}
